home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DJGPP / CBGRX103.ZIP / contrib / libgrx / test / resize.c < prev    next >
Text File  |  1993-12-06  |  3KB  |  131 lines

  1. /** 
  2.  ** RESIZE.C 
  3.  **
  4.  **  Copyright (C) 1992, Csaba Biegl
  5.  **    820 Stirrup Dr, Nashville, TN, 37221
  6.  **    csaba@vuse.vanderbilt.edu
  7.  **
  8.  **  This file is distributed under the terms listed in the document
  9.  **  "copying.cb", available from the author at the address above.
  10.  **  A copy of "copying.cb" should accompany this file; if not, a copy
  11.  **  should be available from where this file was obtained.  This file
  12.  **  may not be distributed without a verbatim copy of "copying.cb".
  13.  **  You should also have received a copy of the GNU General Public
  14.  **  License along with this program (it is in the file "copying");
  15.  **  if not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  16.  **  Cambridge, MA 02139, USA.
  17.  **
  18.  **  This program is distributed in the hope that it will be useful,
  19.  **  but WITHOUT ANY WARRANTY; without even the implied warranty of
  20.  **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21.  **  GNU General Public License for more details.
  22.  **/
  23.  
  24.  
  25. #if defined(__GNUC__) && !defined(near)
  26. # define near
  27. # define far
  28. # define huge
  29. #endif
  30.  
  31. #define UCP unsigned char far *
  32.  
  33. void resize(UCP src,int soff,int oldx,int oldy,UCP dst,int doff,int newx,int newy)
  34. {
  35.     UCP newpt;
  36.     UCP oldpt;
  37.     int pt1,pt2;
  38.     int sum,fac;
  39.     int xx,yy;
  40.     int oo,nn;
  41.  
  42.     if(oldx < newx) {
  43.         oo = oldx - 1;
  44.         nn = newx - 1;
  45.         for(yy = 0; yy < oldy; yy++) {
  46.         oldpt = src + yy*soff + oo;
  47.         newpt = dst + yy*doff + nn;
  48.         pt2 = *oldpt;
  49.         pt1 = *--oldpt;
  50.         *newpt = pt2;
  51.         xx = fac = nn;
  52.         while(--xx > 0) {
  53.             if((fac -= oo) < 0) {
  54.             fac += nn;
  55.             pt2 = pt1;
  56.             pt1 = *--oldpt;
  57.             }
  58.             *--newpt = (pt1*(nn-fac) + pt2*fac) / nn;
  59.         }
  60.         *--newpt = pt1;
  61.         }
  62.         src  = dst;
  63.         soff = doff;
  64.     }
  65.     if(oldx > newx) {
  66.         for(yy = 0; yy < oldy; yy++) {
  67.         oldpt = src + yy*soff;
  68.         newpt = dst + yy*doff;
  69.         xx = nn = newx;
  70.         while(--xx >= 0) {
  71.             sum = 0;
  72.             oo  = oldx;
  73.             while(oo > 0) {
  74.             if(nn == 0) { nn = newx; oldpt++; }
  75.             if((fac = nn) > oo) fac = oo;
  76.             sum += fac * (*oldpt);
  77.             nn -= fac;
  78.             oo -= fac;
  79.             }
  80.             *newpt++ = sum / oldx;
  81.         }
  82.         }
  83.         src  = dst;
  84.         soff = doff;
  85.     }
  86.     if(oldy < newy) {
  87.         nn = newy - 1;
  88.         oo = oldy - 1;
  89.         src += oo*soff;
  90.         dst += nn*doff;
  91.         for(xx = 0; xx < newx; xx++) {
  92.         oldpt = src + xx;
  93.         newpt = dst + xx;
  94.         fac = yy = nn;
  95.         pt2 = *oldpt;
  96.         pt1 = *(oldpt -= soff);
  97.         *newpt = pt2;
  98.         while(--yy > 0) {
  99.             if((fac -= oo) < 0) {
  100.             fac += nn;
  101.             pt2 = pt1;
  102.             pt1 = *(oldpt -= soff);
  103.             }
  104.             *(newpt -= doff) = (pt1*(nn-fac) + pt2*fac) / nn;
  105.         }
  106.         *(newpt -= doff) = pt1;
  107.         }
  108.     }
  109.     if(oldy > newy) {
  110.         for(xx = 0; xx < newx; xx++) {
  111.         oldpt = src + xx;
  112.         newpt = dst + xx;
  113.         yy = nn = newy;
  114.         while(--yy >= 0) {
  115.             sum = 0;
  116.             oo  = oldy;
  117.             while(oo > 0) {
  118.             if(nn == 0) { nn = newy; oldpt += soff; }
  119.             if((fac = nn) > oo) fac = oo;
  120.             sum += fac * (*oldpt);
  121.             nn -= fac;
  122.             oo -= fac;
  123.             }
  124.             *newpt = sum / oldy;
  125.             newpt += doff;
  126.         }
  127.         }
  128.     }
  129. }
  130.  
  131.